package edu.gdin.ecommerce.model;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import edu.gdin.ecommerce.util.DateUtil;
import edu.gdin.ecommerce.util.DicConverter;

/**
 * Account entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "t_account", catalog = "ecommerce")
public class Account implements java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = -3866869567844650816L;
	private Integer accountId;
//	private Integer customerId;
	private String name;
	private Integer status;
	private Double balance;
	private Double singleExpense;
	private Double creditAmount;
	private Double creditLeft;
	private Integer currency;
	private Integer score;
	private Integer balanceWarn;
	private Date createTime;
	private Date updateTime;
	private String accountDesc;
	
	private Customer customer;

	// Constructors

	/** default constructor */
	public Account() {
	}

	/** full constructor */
	public Account(Integer accountId, String name, Integer status,
			Double balance, Double singleExpense, Double creditAmount,
			Double creditLeft, Integer currency, Integer score,
			Integer balanceWarn, Date createTime, Date updateTime,
			String accountDesc, Customer customer) {
		super();
		this.accountId = accountId;
		this.name = name;
		this.status = status;
		this.balance = balance;
		this.singleExpense = singleExpense;
		this.creditAmount = creditAmount;
		this.creditLeft = creditLeft;
		this.currency = currency;
		this.score = score;
		this.balanceWarn = balanceWarn;
		this.createTime = createTime;
		this.updateTime = updateTime;
		this.accountDesc = accountDesc;
		this.customer = customer;
	}

	// Property accessors
	@Id
	@GeneratedValue
	@Column(name = "ACCOUNT_ID", unique = true, nullable = false)
	public Integer getAccountId() {
		return this.accountId;
	}

	public void setAccountId(Integer accountId) {
		this.accountId = accountId;
	}


	@Column(name = "NAME", nullable = false, length = 20)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "STATUS", nullable = false)
	public Integer getStatus() {
		return this.status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	@Column(name = "BALANCE", nullable = false, precision = 12)
	public Double getBalance() {
		return this.balance;
	}

	public void setBalance(Double balance) {
		this.balance = balance;
	}

	@Column(name = "SINGLE_EXPENSE", nullable = false, precision = 12)
	public Double getSingleExpense() {
		return this.singleExpense;
	}

	public void setSingleExpense(Double singleExpense) {
		this.singleExpense = singleExpense;
	}

	@Column(name = "CREDIT_AMOUNT", nullable = false, precision = 12)
	public Double getCreditAmount() {
		return this.creditAmount;
	}

	public void setCreditAmount(Double creditAmount) {
		this.creditAmount = creditAmount;
	}

	@Column(name = "CREDIT_LEFT", precision = 12)
	public Double getCreditLeft() {
		return this.creditLeft;
	}

	public void setCreditLeft(Double creditLeft) {
		this.creditLeft = creditLeft;
	}

	@Column(name = "CURRENCY", nullable = false)
	public Integer getCurrency() {
		return this.currency;
	}

	public void setCurrency(Integer currency) {
		this.currency = currency;
	}

	@Column(name = "SCORE")
	public Integer getScore() {
		return this.score;
	}

	public void setScore(Integer score) {
		this.score = score;
	}

	@Column(name = "BALANCE_WARN", nullable = false)
	public Integer getBalanceWarn() {
		return this.balanceWarn;
	}

	public void setBalanceWarn(Integer balanceWarn) {
		this.balanceWarn = balanceWarn;
	}

	@Column(name = "CREATE_TIME", nullable = false, length = 19)
	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "UPDATE_TIME", length = 19)
	public Date getUpdateTime() {
		return this.updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	@Column(name = "ACCOUNT_DESC", length = 200)
	public String getAccountDesc() {
		return this.accountDesc;
	}

	public void setAccountDesc(String accountDesc) {
		this.accountDesc = accountDesc;
	}


	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "CUSTOMER_ID", nullable = false)
	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	
	public String createTimeToString(){
		SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
		return  fmt.format(createTime);
	}
	
	public String balanceWarm(){
		return DicConverter.dicMapConvert("DIC_BALANCE_WARN", this.getBalanceWarn());
	}

}